package com.gsafety.wellsfort.controller.knowledge;

import com.gsafety.wellsfort.common.util.ApiResponse;
import com.gsafety.wellsfort.domain.dto.ids.MaterialIdDTO;
import com.gsafety.wellsfort.domain.dto.material.MaterialDTO;
import com.gsafety.wellsfort.domain.dto.material.MaterialQueryDTO;
import com.gsafety.wellsfort.domain.vo.TeachingMaterialVO;
import com.gsafety.wellsfort.service.knowledge.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "教材管理",description = "教材管理接口")
@RestController
@Slf4j
@RequestMapping("/api/material")
public class MaterialController {
    @Autowired
    private MaterialService materialService;
    @ApiOperation(value="保存教材")
    @PostMapping("/save")
    public ApiResponse<MaterialDTO> saveMaterial(@RequestBody MaterialDTO materialDto){
        return materialService.saveMaterial(materialDto);
    }

    @ApiOperation(value="删除教材")
    @PostMapping("/remove")
    public ApiResponse deleteMaterial(@RequestBody MaterialIdDTO idDTO){
        return materialService.deleteByMaterialId(idDTO.getMaterialId());
    }

    @ApiOperation(value="查看或编辑教材")
    @PostMapping("/get")
    public ApiResponse<TeachingMaterialVO> getMaterial(@RequestBody MaterialIdDTO idDTO){
        return materialService.getMaterial(idDTO.getMaterialId());
    }

    @ApiOperation(value="查询教材")
    @PostMapping("/list")
    public ApiResponse<List<TeachingMaterialVO>> findByPageParams(@RequestBody MaterialQueryDTO dtoParams){
        return materialService.findByPageParams(dtoParams);
    }

}
